<h1 class="page-header">
    <small>编辑员工信息</small>
</h1>
<hr/>
<div class="panel panel-inverse" data-sortable-id="form-stuff-1">
    <div class="panel-heading">
        <h4 class="panel-title">员工信息</h4>
    </div>
    <div class="panel-body">
        <form class="form-horizontal" id="staffForm" name="staffForm" method="post">
            <div class="form-group">
                <input type="hidden" id="id" name="id" value="${staff.id}">
                <label class="col-md-3 control-label"><span class="requiredstar">* </span>姓名</label>
                <div class="col-md-3">
                    <input type="text" id="realName" class="form-control" name="realName" placeholder="姓名" maxlength="20" value="${staff.realName}" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label"><span class="requiredstar">* </span>手机号</label>
                <div class="col-md-3">
                    <input type="text" id="mobile" class="form-control" name="mobile" placeholder="手机号" maxlength="20" value="${staff.mobile}" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">所属店铺</label>
                <div class="col-md-3">
                    <select class="form-control" name="storeId" id="storeId">
                        <option value="0" <#if 0 == staff.storeId > selected</#if> >全部</option>
                        <#if storeList?has_content && storeList?exists>
                        <#list storeList as pf>
                        <option value="${pf.id}" <#if pf.id == staff.storeId > selected</#if> >${pf.name}</option>
                        </#list>
                        </#if>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">备注信息</label>
                <div class="col-md-5">
                    <textarea rows="5" class="form-control" id="description" name="description" maxlength="1000" placeholder="备注信息">${staff.description}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">状态</label>
                <div class="col-md-2">
                    <select class="form-control" id="status" name="status">
                        <option value="A" <#if (staff.auditedStatus == 'A')>selected</#if>>启用</option>
                        <option value="N" <#if (staff.auditedStatus != 'A')>selected</#if>>禁用</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label"></label>
                <div class="col-md-9">
                    <button type="button" id="submitButton" class="btn btn-sm btn-success">提交</button>
                    <button type="button" class="btn btn-sm btn-danger"
                            onclick="getData('${rc.contextPath}/backend/staff/queryList','displayArea')">返回
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="application/javascript">

    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写手机号码");

    $(function () {
        $('#submitButton').click(function () {
            $('#staffForm').submit();
        });

        $('#staffForm').validate({
            rules: {
                realName: {
                    required : true,
                    maxlength : 20
                },
                mobile: {
                    required : true,
                    minlength : 11,
                    isMobile : true
                }

            },
            messages: {
                realName: {
                    required :  "姓名需要填写",
                    maxlength : "不能大于20个字符"
                },
                mobile: {
                    required : "请输入手机号",
                    minlength : "不能小于11个字符",
                    isMobile : "请正确填写手机号码"
                }
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parent());
            },
            submitHandler: function () {
                postDataByFormParams('${rc.contextPath}/backend/staff/doEdit', 'displayArea', 'staffForm');
            }
        })
    })
</script>

